<?php
defined ( 'IN_SYS' ) or die ( 'Restricted Access' );
# In PHP 5.2 or higher we don't need to bring this in
if (!function_exists('json_encode')) {
	require_once SYS_LIB_KERNEL.'json'.DS.'JSON.php';
}

/**
 * @desc	Get Microtime
 * @return 	float
 */
function sys_get_microtime() {
	list ( $usec, $sec ) = explode ( ' ', microtime () );
	return (( float ) $usec + ( float ) $sec);
}

function sys_is_number ($input=NULL) {
	return TRUE;
}

function sys_is_integer ($input=NULL) {
	return preg_match('@^[-]?[0-9]+$@',$input) === 1;
}

function sys_is_email ($input=NULL) {
	return TRUE;
}

function sys_is_url ($input=NULL) {
	return TRUE;
}

function sys_is_tel ($input=NULL) {
	return TRUE;
}

/**
 * Generator password
 * @param string $str input
 * @param int $LEN lenght pass output
 * @return password with lenght = $LEN
 */
function sys_password_generator($str='', $LEN=10) {
	$CODE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
	$str = md5($str.md5($LEN));
	$CODE_len = strlen($CODE);
	$str_len = strlen($str);
	
	$total = 0;
	for ($i=0; $i<$str_len; $i++) {
		$total += strpos($CODE, $str{$i});
	}
	
	$result = '';
	$num = 0;
	while ($num < $LEN) {
		$num ++;
		$pos = $total % $CODE_len;
		$result.= $CODE{$pos};
		
		$total = $total + $num * $pos;
	}
	
	return $result;
}

function sys_pathinfo ($file='') {
	if (defined('PATHINFO_FILENAME')) return pathinfo($file);
	
    $path_info = pathinfo($file);
    $path_info['filename'] = substr($path_info['basename'], 0, -strlen('.'.$path_info['extension']));
    return $path_info;
}

/**
 * return content of file
 */
function sys_file_get_contents ($path='') {
	if (file_exists($path)) {
		return @file_get_contents($path);
	}
	return NULL;
}